<template>
	<view class="mainbgc">
		<view class="mainpadding">
			<view class="flexcenter" style="margin-top: 200rpx;" v-if="!list.data.length">
				<view class="placeimage"></view>
			</view>
			<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id">
				<view class="flexbetween">
					<view class="flexleft">
						<view class="avatarimg">
							<image :src="item.user.avatar_text" mode=""></image>
						</view>
						<view class="">
							<view class="strongtext">{{item.user.nickname}}</view>
							<view class="huitext">{{item.user.jointime_text}}</view>
						</view>
					</view>
					<view class="xiazai" @click="downloadFun(item.user.grjl_text)">下载附件</view>
				</view>
				
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				listid:""
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this;
				httpRequest.request('/api/zp/myGetJl', 'GET', {
					page: page || 1,
					limit: _this.limit,
					zp_id:this.listid
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
			
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			downloadFun(enclosure) {
				var that = this
				//加载框动画
				uni.showLoading({
					title: '正在下载……'
				});
				uni.downloadFile({
					url: enclosure, //下载地址接口返回
					success: (data) => {
						if (data.statusCode === 200) {
							//隐藏加载框
							uni.hideLoading();
							//文件保存到本地
							uni.saveFile({
								tempFilePath: data.tempFilePath, //临时路径
								success: function(res) {
									uni.showToast({
										icon: 'success',
										mask: true,
										// title: '文件已保存：' + res.savedFilePath, //保存路径
										title: '下载成功',
										duration: 2000,
									});
									//自动打开文档查看
									setTimeout(() => {
										var filePath = res.savedFilePath;
										uni.openDocument({ //新开页面打开文档，支持格式：doc, xls, ppt, pdf, docx, xlsx, pptx。
											filePath: filePath,
											showMenu: true,
											success: function(res) {
											}
										});
									}, 2000)
								}
							});
						}
					},
					fail: (err) => {
						console.log(err);
						uni.showToast({
							icon: 'none',
							mask: true,
							title: '文件下载失败',
						});
					},
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.mainpadding2{
		padding: 0 30rpx;
		box-sizing: border-box;
	}
	.avatarimg{
		width: 77rpx;
		height: 77rpx;
		border-radius: 50%;
		margin-right: 30rpx;
		image{
			border-radius: 50%;
			width: 100%;
			height: 100%;
		}
	}
	.huitext{
		margin-top: 10rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #626365;
	}
	.xiazai{
		border-radius: 50rpx;
		border: 1rpx solid #228DFF;
		text-align: center;
		padding: 10rpx 40rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #228DFF;
	}
</style>
